package app.controlador;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Vector;

import utils.ArticuloADespacharXML;
import app.modelo.BusinessdelegateCD;

import com.thoughtworks.xstream.XStream;

import framework.controlador.Controlador;
import framework.modelo.Businessdelegate;
import framework.vista.Vista;

public class ControladorSolicitudDeDistribucion extends Controlador
{
	public ControladorSolicitudDeDistribucion(Businessdelegate mod, Vista v)
	{
		super(mod, v);
	}

	@SuppressWarnings("deprecation")
	public void obtenerSolicitudDeDistribucionXML(String absolutePathXML)
	{
		StringBuffer contenido = null;
		ArticuloADespacharXML articuloadespachar=null;
		DataInputStream input=null;
			
		try
		{
			FileInputStream fileInputStream=new FileInputStream(absolutePathXML);
			input = new DataInputStream(fileInputStream);
			
			while(true)
			{
				contenido=new StringBuffer();
				contenido.append(input.readLine());
				contenido.append(input.readLine());
				contenido.append(input.readLine());
				contenido.append(input.readLine());
				contenido.append(input.readLine());
			
				XStream xstream=new XStream();
				xstream.alias("ArticuloADespachar", ArticuloADespacharXML.class);
				articuloadespachar=(ArticuloADespacharXML)xstream.fromXML(contenido.toString());
			
				((BusinessdelegateCD)(this.getModelo())).enviarSolicitud(articuloadespachar);
			}
		}
		catch(Exception e)
		{
			System.out.println("Se leyo XML SolDist");

			try{
				input.close();
			}catch(IOException e1){
				System.out.println("Error al cerrar el XML SolDist");
			}
		}
	}

	// Obtiene a enviar y pendientes
	@SuppressWarnings("unchecked")
	public Vector obtenerAEnviarYPendientes()
	{
		return ((BusinessdelegateCD)(this.getModelo())).obtenerAEnviarYPendientes();
	}
}
